package com.carkeeper.controller;


import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.carkeeper.pojo.Blog;
import com.carkeeper.pojo.BlogCategory;
import com.carkeeper.service.DiscoverService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value = "zmz")
@RestController
@RequestMapping("/discover")
@CrossOrigin
public class DiscoverController {


    @Autowired
    private DiscoverService discoverService;



    /**
     * 多条件查询
     *
     * @param map
     * @return
     */
    @GetMapping("/multipartFind/{currentPage}/{pageSize}")
    public Result<PageInfo<Blog>> multipartConditionFind(@RequestParam Map map, @PathVariable("currentPage") String currentPage,@PathVariable("pageSize") String pageSize) {
        PageInfo<Blog> pageInfo = discoverService.multipartConditionFindBlog(map, currentPage, pageSize);
        return new Result<>(true, StatusCode.OK, "查询成功！", pageInfo);
    }


    /**
     * 查询全部分类
     *
     * @return
     */
    @GetMapping("/findAllCategory")
    public Result<List<BlogCategory>> findAllCategory() {
        List<BlogCategory> categoryList = discoverService.findAllCategory();
        return new Result<>(true, StatusCode.OK, "查询分类成功！", categoryList);
    }


    /**
     * 添加文稿
     * @param map
     * @return
     */
    @PostMapping("/addBlog")
    public Result addBlog(@RequestBody Map<String, String> map) {
        return discoverService.addBlog(map);
    }


    /**
     * 查询分类对应的配件或服务详情
     * @param type
     * @return
     */
   /* @GetMapping("/findKnowledgeByCategory/{type}")
    public Result findKnowledgeByCategory(@PathVariable("type") String type) {
        return discoverService.findKnowledgeByCategory(type);
    }*/


    /**
     * 根据id查询文稿详情
     * @param id
     * @return
     */
    @GetMapping("/findBlogById/{id}")
    public Result<Blog> findBlogById(@PathVariable("id") String id) {
        return discoverService.findBlogById(id);
    }


    /**
     * 修改文稿
     * @param id
     * @return
     */
    @PutMapping("/update/{id}")
    public Result update(@PathVariable("id") String id) {
        return null;
    }



}
